<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/11/11
 * Time: 10:13
 */

namespace business\bigdata\model;

use yii\base\Model;

class SupplierModel extends Model
{
    /**
     * @var string 供应商id
     */
    public $supplierId;

    /**
     * @var string 公司名称
     */
    public $supplierName;

    /**
     * @var string 公司简介
     */
    public $supplierIntroduce;

    /**
     * @var string 注册资本
     */
    public $registCapi;

    /**
     * @var string 公司标签
     */
    public $supplierTag;

    /**
     * @var string 公司所在省份code
     */
    public $supplierProvinceCode;

    /**
     * @var string 公司所在省份名称
     */
    public $supplierProvinceName;

    /**
     * @var string 公司城市code
     */
    public $supplierCityCode;

    /**
     * @var string 公司城市名称
     */
    public $supplierCityName;

    /**
     * @var string 公司地址
     */
    public $supplierLocationName;

    /**
     * @var array 公司服务分类一级code
     */
    public $supplierBusinessCode1 = [];

    /**
     * @var array 公司服务分类一级名称
     */
    public $supplierBusinessName1 = [];

    /**
     * @var array 公司服务分类二级code
     */
    public $supplierBusinessCode2 = [];

    /**
     * @var array 公司服务分类二级名称
     */
    public $supplierBusinessName2 = [];

    /**
     * @var array 公司服务分类三级code
     */
    public $supplierBusinessCode3 = [];

    /**
     * @var array 公司服务分类三级名称
     */
    public $supplierBusinessName3 = [];

    /**
     * @var string 供应商服务分类名称
     */
    public $supplierBusinessName = '';

    /**
     * @var string 修改时间
     */
    public $update_timestamp = '';

    /**
     * @var array 公司项目案例
     */
    public $supplierProjectCase = [];

    /**
     * @var array 公司服务资质名称
     */
    public $supplierQualificationName = [];

    /**
     * @var array 公司服务资质code
     */
    public $supplierQualificationCode = [];

    /**
     * @var array 搜索匹配的相关案例名称
     */
    public $matchedProjectName = [];

    /**
     * @var int 搜索匹配的相关案例数量
     */
    public $matchedProjectNumber;

    /**
     * @var array 百强战略供应商
     */
    public $topStrategySupplier = [];

    /**
     * @var array 百强合作供应商
     */
    public $topDeveloper = [];

    /**
     * @var array top级标签
     */
    public $topBusinessArea = [];

    /***
     * @var array 榜上有名名单
     */
    public $boardList = [];

    public $pointBusiness = 0;// 大数据工商信息得分

    public $pointQualifications = 0;//大数据资质信息得分

    public $pointCase = 0;//大数据案例得分

    public $hasProduct = 0;//产品信息是否存在

    public $pointContact = 0; //大数据联系方式得分

    public $pointCooperative = 0; //大数据合作记录得分

    public $hasRegulatory = 0;//是否监管备案

    public $hasRichcase = 0; //是否案例丰富

    public $boardCout = 0;//榜上有名个数

    public $supplierProjectCaseNumber = 0; //公司项目案例数量

    public $cooperationDevelopersNumber = 0; //开发商合作记录数量

    public $qualificationNumber = 0;// 认证资质数量

    public $memberNumber = 0;// 专家数量

    public $linkNumber = 0;// 联系人数量

    //public $recommendNumber = 0;//推荐数量

    //public $viewNumber = 0;// 浏览数

    //public $lastActiveTime = 0;// 最后活动时间（Unix Timestamp）

    public $registCapiRmb;// 人民币格式的注册资本

    public $isPreciseMatch;//精准匹配
    /**
     * @var string 公司经营范围
     */
    public $supplierScope;
    /**
     * @var array 搜索匹配的相关案例名称
     */

    public $matchedTopDeveloper = [];

    /**
     * @var int 搜索匹配的相关案例数量
     */
    public $matchedTopDeveloperNumber;

    public $matchedTopBusinessArea = [];

    public $matchedTopBusinessAreaNumber;

    public $customProperty;

    public $score;

    public function rules()
    {
        return [
            [array_keys($this->getAttributes()), 'safe'],
        ];
    }

    /**
     * 填充供应商大数据model
     * @param $singleInfo
     */
    public function fill($singleInfo)
    {
        $this->supplierId = isset($singleInfo["id"]) ? $singleInfo["id"] : null;
        $this->supplierName = isset($singleInfo["name"]) ? $singleInfo["name"] : null;
        $this->supplierIntroduce = isset($singleInfo["profile"]) ? $singleInfo["profile"] : null;
        $this->supplierScope = isset($singleInfo["scope"]) ? $singleInfo["scope"] : null;
        $this->registCapi = isset($singleInfo["regist_capi"]) ? $singleInfo["regist_capi"] : null;
        $this->registCapiRmb = isset($singleInfo["num_capi"]) ? intval($singleInfo["num_capi"]) : 0;
        $this->supplierTag = isset($singleInfo["label"]) ? $singleInfo["label"] : null;
        $this->supplierProvinceCode = isset($singleInfo["province"]) ? (float)$singleInfo["province"] : null;
        $this->supplierProvinceName = isset($singleInfo["province_name"]) ? $singleInfo["province_name"] : null;
        $this->supplierCityCode = isset($singleInfo["city"]) ? (float)$singleInfo["city"] : null;
        $this->supplierCityName = isset($singleInfo["city_name"]) ? $singleInfo["city_name"] : null;
        $this->supplierBusinessName = isset($singleInfo["three_cate_name_list"]) ? $singleInfo["three_cate_name_list"] : null;
        if (isset($singleInfo["three_cate_code_list"]) && $singleInfo["three_cate_code_list"] != 0) {
            $this->supplierBusinessCode3 = explode(",", $singleInfo["three_cate_code_list"]);
        }
        $this->pointBusiness = isset($singleInfo["business_score"]) ? (float)$singleInfo["business_score"] : 0;
        $this->pointCase = isset($singleInfo["project_score"]) ? (float)$singleInfo["project_score"] : 0;
        $this->pointContact = isset($singleInfo["contact_score"]) ? (float)$singleInfo["contact_score"] : 0;
        $this->pointCooperative = isset($singleInfo["cooperation_score"]) ? (float)$singleInfo["cooperation_score"] : 0;
        $this->hasProduct = isset($singleInfo["product_score"]) ? (float)$singleInfo["product_score"] : 0;
        $this->pointQualifications = isset($singleInfo["qualification_score"]) ? (float)$singleInfo["qualification_score"] : 0;
        $this->hasRegulatory = isset($singleInfo["supervise_score"]) ? (float)$singleInfo["supervise_score"] : 0;
        $this->update_timestamp = isset($singleInfo["update_timestamp"]) ? $singleInfo["update_timestamp"] : null;
    }

    /**
     * 检查供应商信息是否符合建立索引条件
     * @return bool
     */
    public function checkCondition()
    {
        if (empty($this->supplierName)) {
            return false;
        }
        return true;
    }
}
